<?php
/**
 * Created by PhpStorm
 * User: long
 * Date: 2019/11/28
 * Time: 13:44
 */

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use EasyWeChat\Kernel\Messages\Text;
use Illuminate\Support\Facades\Log;

class WeChatController extends Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function serve()
    {
        $this->app->server->push(function ($message) {
            return "欢迎关注 overtrue！";
        });
        $message = $this->app->server->getMessage();
        Log::info('message:' . json_encode($message, JSON_UNESCAPED_UNICODE));
        return $this->app->server->serve();
    }

    public function send()
    {
        $text = new Text('您好,关注者');
        return $this->app->customer_service->message($text)->to('o5Npcw-khTKlXZBjy64_lch-eHkg')->send();
    }

    public function sendAll()
    {
        return $this->app->broadcasting->sendText("大家好！欢迎使用 EasyWeChat。");
    }
}